package com.example.week7_springdata.controller.service;

import com.example.week7_springdata.entity.Supplier;
import com.example.week7_springdata.repo.SupplierRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author 浆布
 * @description 供应商业务逻辑
 */
@Component
public class SupplierService {

    @Autowired
    private SupplierRepo supplierRepo;

    public SupplierService() {
        // TODO document why this constructor is empty
    }

    public Supplier addSupplier(Supplier supplier) {
        return supplierRepo.saveAndFlush(supplier);
    }

    public Supplier getSupplierById(Long id) {
        return supplierRepo.findById(id).orElse(null);
    }

    public Supplier updateSupplier(Supplier supplier) {
        return supplierRepo.save(supplier);
    }

    public void deleteSupplierById(Long id) {
        supplierRepo.deleteById(id);
    }
}
